<!-- pageSelection.php
      Looks at the URI and fetches the apropriate
       page to be displayed in the index.php; This page helped me
        set up this little bit of code
         http://www.webcheatsheet.com/PHP/get_current_page_url.php -->

<!--Takes in: Input from menu
    Returns: Main Body Content of page-->

<!--Function Begins-->
<?php

if (isset($_GET['iframe'])) {

	$ifurl = $_GET['iframe'];   //get page from url and add .php at the end
	echo'<iframe src ="'.$ifurl.'" class="iframe"> iframes not supported</iframe>';
	echo'<div></div><br/>'; //added so the wunderbar takes the height of the iframe into account.

}
else{

$page = ".php";
$section = "";

if (isset($_GET['page']))
	$page = $_GET['page'].".php";   //get page from url and add .php at the end


if (isset($_GET['section']))
	$section = $_GET['section'];   //get section from url

//add '/' at the end of section if present
if ($section != null) { 
   $section.="/"; 

      //weird validation fix for 3 links in the menu
      if(isset($_GET['amp;page'])){
            $page = $_GET['amp;page'].".php";}

        else{$page = $_GET['page'].".php";}
                         }

$load = FALSE;



				/*********************************************************************/

				/**********   calling the Perl script        *************************/

				/*********************************************************************/

				$cmd = './../perllib/permissionCheck.pl ' .EscapeShellArg($page)." ".EscapeShellArg($_SESSION['group']);
				$returnValue = exec($cmd,$output,$result);

				//if user is authenticated
				if ($result == 0)
				{

					if ($output[1] == "True")
					{
						$load = TRUE;
					}
					else
					{
						$load = FALSE;
					}


				}
				//if not authenticated
				else
				{
					// There is an Internal Error. so No Page load is Allowed.
					$load = FALSE;


				}


			/*****************************************************************/
			/*****************************************************************/

//changes link for amdin directory
if ($section == "admin/" ) { $section = "../../".$section."menu/"; }
if ($page == ".php"){ include("services.php"); }   //refers index.php to services.php


else {

 $path = "../phplib/";
  if(!file_exists($path.$section.$page))
   {
      echo('<div class="errorMessage center XLbodycopy"><br/><br/>'.$section.$page.'</div>');
      echo('<div class="errorMessage center XLbodycopy"><br/><br/>Well this is embarrassing, the file was not found.</div>');
   }

   elseif(!$load) {

		   echo('
                   <div class="errorMessage center">
		   <br/><br/>
		   <img src="http://www.usalinux.org/ind.jpg" alt="ACCESS DENIED"/>
		   <!-- This images was taken from www.usalinux.org --></div>');

		   if(isset($_SESSION["Username"])) { echo('<p class="header1">You do not have access to this page.</p>'); }

		   else {
					echo('
						   <p class="header1">Please log in to view this page.</p>
						   The login is conveniently situated in the upper right-hand corner on all pages of this site.
						   <br/><br/><br/><br/>
						   <div>');
				}
   }
   else { include($section.$page); }

}
}
?>
<!--Function Ends-->
